<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>用户管理</title>
		<link href="<%=application.getContextPath()%>/nresources/ued/css/all-src.css" type="text/css" rel="stylesheet" />
		<%@include file="/WEB-INF/ibnms/common/easyui.jsp" %>
		<%@include file="/WEB-INF/ibnms/common/jqgrid.jsp"%>
		<%@ include file="/WEB-INF/ibnms/common/jsCommonVariables.jsp"%>
	</head>
    <body>
        <div class="form-wrapper">
        	<div class="block02">
        		<div class="title-style02">
						<input type="button" class="btn-style02" id="btn-add" value="增加">&nbsp;&nbsp;
						<input type="button" class="btn-style02" id="btn-edit" value="修改">&nbsp;&nbsp;
						<input type="button" class="btn-style02" id="btn-del" value="删除">
				</div>
	            <table id="gridTable">
				</table>
				<div id="gridPager">
				</div>
				<form name="theForm" >
				</form>
			</div>
        </div>
	    <script type="text/javascript">
			$(function(){$("#gridTable").jqGrid({
					url: "porletListQueryJson.do",
					datatype: "json",
					mtype: "POST",
					height: "100%",
					autowidth: true,
					colNames:['Panel ID', 'Panel 名称', '默认路径', '所属角色', '描述'],
					colModel:[
						{name:'PORLET_ID',index:'PORLET_ID'},
						{name:'TITLE',index:'TITLE'},
						{name:'CONTENT_URL',index:'CONTENT_URL'},
						{name:'ROLE_NAME',index:'ROLE_NAME'},
						{name:'DESCRIPTION',index:'DESCRIPTION'}
					],
					viewrecords: true,
					rowNum: 15,
					rowList: [10,15,30],
					jsonReader: {
						root: 'rows',
						page: 'page',
						total: 'total',
						records: 'records',
						repeatitems: false,
						subgrid: {
					        root: 'rows',
							page: 'page',
							total: 'total',
							records: 'records',
							repeatitems: false
					    }      
					},
					pager: "#gridPager",
					hidegrid: true,
					multiselect: true
				});
				
			}); 
			
			
			$("#btn-add").click(function(){
				$("form[name='theForm']").append("<input type='hidden' name='cmd' value='add'/>");
				$("form[name='theForm']").attr("action","<s:url action='addPorlet' namespace='/'/>?cmd=add").submit();
			});
			$("#btn-del").click(function(){
			 	var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
                if (idArr.length == 0) {
                    alert("请先选择要删除的记录!");
                    return;
                }
				if(confirm("是否删除所选的记录?")){
	                var PORLET_ID = "";
                    for (var one in idArr){
                    	var data = jQuery("#gridTable").jqGrid('getRowData',idArr[one]);
                    	PORLET_ID += data.PORLET_ID + ",";
                    }
                    if(PORLET_ID.length>0){
                    	PORLET_ID = PORLET_ID.substring(0,PORLET_ID.length-1);
                    }

					$.ajax({
						type: "POST",
						async: false,
						url: "<s:url action="deletePorlet" namespace='/'/>?porletIds="+PORLET_ID,
						success: function(data){
	                        if (data != "true"){
								alert(data);
	                        } 
	                        $("#gridTable").trigger('reloadGrid');
						},
						error:function(xhr){  
							show_error(xhr);
						}
					});	
                }
			});
			$("#btn-edit").click(function() {
				var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
				switch (idArr.length) {
					case 0:
						alert("请先选择要修改的任务!");
						break;
					case 1:
						var data = jQuery("#gridTable").jqGrid('getRowData',idArr[0]);
						var porletId = data.PORLET_ID;
						$("form[name='theForm']").append("<input type='hidden' name='cmd' value='update'/>");
						$("form[name='theForm']").append("<input type='hidden' name='porletId' value='"+porletId+"'/>");
						$("form[name='theForm']").attr("action","<s:url action='addPorlet' namespace='/'/>");
						$("form[name='theForm']").submit();
						break;
					default:
						alert("一次只能修改一条任务!");
				}
			}); 
		</script>
    </body>
</html:html>
